package com.logistics.inventory.entity.model;

import com.logistics.inventory.entity.domain.Inventory;
import com.logistics.map.entity.domain.MapComponents;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class InventoryContainerRow {

    private Integer id;

    private String label;

    private BigDecimal x;

    private BigDecimal y;

    private Boolean horizontal = true;

    private List<InventoryDetailRow> goods;

    public static InventoryContainerRow build(Inventory inventory, BigDecimal x, BigDecimal y, MapComponents mapComponents, List<InventoryDetailRow> goods) {
        InventoryContainerRow inventoryContainerRow = new InventoryContainerRow();
        inventoryContainerRow.setId(inventory.getId());
        inventoryContainerRow.setLabel(inventory.getContainer());
        inventoryContainerRow.setX(x);
        inventoryContainerRow.setY(y);
        if(StringUtils.isNotNull(mapComponents)){
            String[] size = mapComponents.getSize().split(",");
            inventoryContainerRow.setHorizontal(Integer.parseInt(size[0]) > Integer.parseInt(size[1]));
        }
        inventoryContainerRow.
                setGoods(goods);
        return inventoryContainerRow;
    }
}
